package com.fh.model;


import java.util.*;

/**
 * 创建者：shanlin
 * 创建时间：2017/12/23 10:04
 * @author
 **/
public class OnlineCounter {
	
	private static String currentIp;
	
	private static HashSet<String> ipList = new HashSet<>();
	
	private static Map<String,String> idToIp = new HashMap<>(32);
	
	/**
	 * 在线人数
	 */
	private static long online = 0;
	
	public static long getOnline() {
		return online;
	}
	
	public static void add(String sessionId,String ip) {
		setCurrentIp(ip);
		idToIp.put(sessionId,ip);
		ipList.add(ip);
		online =  idToIp.keySet().size();
	}
	
	public synchronized static void sub(String sessionId) {
		idToIp.remove(sessionId);
		online =  idToIp.keySet().size();
	}
	
	public static String getCurrentIp() {
		return currentIp;
	}
	
	public static void setCurrentIp(String currentIp) {
		OnlineCounter.currentIp = currentIp;
	}
	
	public static HashSet<String> getIpList() {
		return ipList;
	}
}
